#ifndef NINESQUAREGRID_H
#define NINESQUAREGRID_H

#include <QWidget>
#include "sudoku_ui_global.h"
#include <map>
#include <QPaintEvent>
#include <QResizeEvent>

namespace sudoku_ui {

    class SudokuCell;
    /**
     * @brief The NineSquareGrid class  九宫格窗体
     */
    class SUDOKU_UI_EXPORT NineSquareGrid : public QWidget
    {
        Q_OBJECT
    public:
        explicit NineSquareGrid(QWidget *parent = nullptr);
        explicit NineSquareGrid(int index, QWidget * parent = nullptr);
        virtual ~NineSquareGrid();

        void setValue(int index, int value);
        void setHintValue(int index, int value);

        /**
         * @brief value     获取第index个数独单元格的值
         * @param index     取值范围为1~9
         * @return          返回数独单元格的值
         */
        int value(int index);

        /**
         * @brief cell
         * @param index
         * @return
         */
        SudokuCell * cell(int index);

        /**
         * @brief newGame
         */
        void newGame();

        /**
         * @brief index
         * @return
         */
        int index() const;

        static void globalSetLineColor(const QColor& color);
        static const QColor& globalGetLineColor();
        static void globalSetLineWidth(float linewidth);
        static float globalLineWidth();

    private:
        std::map<int, SudokuCell*> m_cells;
        SudokuCell * m_selectCell{nullptr};
        int m_index{-1};
        static QColor g_lineColor;
        static float g_lineWidth;

    signals:

    private slots:
        void onSelectedCell(SudokuCell * cell);

        // QWidget interface
    protected:
        void paintEvent(QPaintEvent *event) override;
        void resizeEvent(QResizeEvent *event) override;
    };

}



#endif // NINESQUAREGRID_H
